package net.javaonfly.core.dispatch;

import java.util.Hashtable;

import net.javaonfly.core.exception.JofException;

public class Router {
	private Hashtable<String,HandlerRoute> routeMap=new Hashtable<String,HandlerRoute>();
	public HandlerRouteExt resolve(String url,String pkg) throws JofException{
		String[] params = url.split("/");
		String op=null;
		if(params.length>3){
			op=params[3];
		}else{
			op="index";
		}
		String key=pkg+"."+params[1]+"."+params[2]+"/"+op;
		String strId="";
		if(params.length>4)
			strId=params[4];
		if (null!=routeMap.get(key)){
			return new HandlerRouteExt(routeMap.get(key),strId);
		}else{
			HandlerRoute newHandlerRoute=HandlerRoute.resolve(url,pkg);
			routeMap.put(key, newHandlerRoute);
			return new HandlerRouteExt(newHandlerRoute,strId);
		}
	}

}
